//
//  PFCommonRectManager.m
//  PrintFamily
//
//  Created by edaihua on 16/3/23.
//  Copyright © 2016年 ___PrintFactory___. All rights reserved.
//

#import "PFCommonRectManager.h"

@implementation PFCommonRectManager

static const CGFloat kRectHeightToWidthRatio  = 1.48;
static const CGFloat kTargetPhotoFrameOriginX = 20.0; // Target frame origin X in MasterViewTableCell
static const CGFloat kTargetPhotoFrameOriginY = 20.0; // Target frame origin Y in MasterViewTableCell

- (PFCommonRectManager*)initWithType:(PhotoPrintType)type boarder:(PhotoBoarder)boarder {
    if (self = [super init]) {
        CGSize screenSize = [AppDelegate getScreenSize];
        CGSize frameSize  = CGSizeZero;
        CGSize photoSize  = CGSizeZero;
        
        self.boarderWidth = boarder == PhotoBoarder_White ? 10.0 : 0;
        
        frameSize.width = screenSize.width - kTargetPhotoFrameOriginX * 2;
        photoSize.width = frameSize.width - self.boarderWidth * 2;
        
        switch (type) {
            case PhotoType_Rectangle_Mini:
            case PhotoType_Rectangle_Medium:
            case PhotoType_Rectangle_Large:
                frameSize.height = frameSize.width * kRectHeightToWidthRatio;
                photoSize.height = frameSize.height - self.boarderWidth * 2;
                break;
                
            case PhotoType_Square:
            case PhotoType_Square_Mini:
            default:
                frameSize.height = frameSize.width;
                photoSize.height = frameSize.height - self.boarderWidth * 2;
                break;
        }
        
        self.frameSize       = frameSize;
        self.targetPhotoSize = photoSize;
    }
    return self;
}

- (CGFloat)getPhotoFrameOriginXInMasterCell {
    return kTargetPhotoFrameOriginX;
}

- (CGFloat)getPhotoFrameOriginYInMasterCell {
    return kTargetPhotoFrameOriginY;
}

+ (CGSize)getMasterCellSizeWithType:(PhotoPrintType)type {
    CGSize cellSize   = CGSizeZero;
    CGSize screenSize = [AppDelegate getScreenSize];
    
    switch (type) {
        case PhotoType_Square_Mini:
        case PhotoType_Square:
            cellSize = CGSizeMake(screenSize.width, screenSize.width);
            break;
        case PhotoType_Rectangle_Mini:
        case PhotoType_Rectangle_Medium:
        case PhotoType_Rectangle_Large:
            cellSize = CGSizeMake(screenSize.width, screenSize.width * kRectHeightToWidthRatio);
            break;
            
        default:
            break;
    }
    
    return cellSize;
}

- (CGRect)getTargetPhotoRectInResizeView {
    CGSize screenSize = [AppDelegate getScreenSize];
    CGRect photoRect  = CGRectZero;
    
    CGFloat photoOriginX = kTargetPhotoFrameOriginX + self.boarderWidth;
    CGFloat photoOriginY = (screenSize.height - self.targetPhotoSize.height) / 2;
    photoRect = CGRectMake(photoOriginX, photoOriginY, self.targetPhotoSize.width, self.targetPhotoSize.height);
    
    return photoRect;
}

@end
